import { Module } from 'vuex'
import { IRoterType } from '@/store/type'
import { IAnalysisType } from '@/store/main/analysis/type'
import { getAnalysisRequest } from '@/service/mian/analysis/analysis'
const analysis: Module<IAnalysisType, IRoterType> = {
  namespaced: true,
  state: {
    count: [],
    sale: [],
    favor: [],
    addressSale: []
  },
  mutations: {
    changeCount(state, list: any) {
      state.count = list
    },
    changeSale(state, list: any) {
      state.sale = list
    },
    changeFavor(state, list: any) {
      state.favor = list
    },
    changeAddressSale(state, list: any) {
      state.addressSale = list
    }
  },
  actions: {
    async getAnalysisPagesData({ commit }) {
      const countRes = await getAnalysisRequest('/goods/category/count')
      commit('changeCount', countRes.data)
      const saleRes = await getAnalysisRequest('/goods/category/sale')
      commit('changeSale', saleRes.data)
      const favorRes = await getAnalysisRequest('/goods/category/favor')
      commit('changeFavor', favorRes.data)
      const addressSaleRes = await getAnalysisRequest('/goods/address/sale')
      commit('changeAddressSale', addressSaleRes.data)
    }
  }
}

export default analysis
